package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.pojo.param.ArticleCategoryParam;
import com.tarena.lbs.content.pojo.param.ArticleContentParam;
import com.tarena.lbs.content.pojo.vo.ArticleCategoryVO;
import com.tarena.lbs.content.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理文章分类 业务模块功能
 */
@Slf4j
@Tag(name = "文章分类管理")
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    @Operation(summary = "新增文章分类")
    @PostMapping("/admin/content/category/insert")
    public Result<Void> addCategory(ArticleCategoryParam articleCategoryParam){
        categoryService.addCategory(articleCategoryParam);
        return Result.success();
    }

    @Operation(summary = "文章分类列表查询")
    @GetMapping("/admin/content/category/list")
    public Result<PageResult<ArticleCategoryVO>> pageList(
            @RequestParam(required = false) String categoryName,
            @RequestParam(required = false) Integer categoryStatus
    ){
        return categoryService.selectCategory(categoryName,categoryStatus);
    }

    @Operation(summary = "修改文章分类")
    @PostMapping("/admin/content/category/update")
    public Result<Integer> updateCategory(ArticleCategoryParam articleCategoryParam){
        return categoryService.updateCategory(articleCategoryParam);
    }

    @Operation(summary = "删除文章分类")
    @PostMapping("/admin/content/category/delete")
    public Result<Void> deleteCategory(@RequestBody ArticleCategoryParam articleCategoryParam){
        categoryService.deleteCategory(articleCategoryParam);
        return Result.success();
    }
}
